package com.view;

import com.controller.PanelLihatDaftarDokumen;
import com.controller.PanelLihatDaftarSurat;
import com.controller.PengendaliPeriksaSuratDokumen;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

public class Dosen_view extends JPanel {

    private JCheckBox jc, jc1, jc2;
    private JLabel label1, label3, label5, label7;
    private JButton but1, but2, but3, but4;
    public JTextField jt1, jt2;
    private ButtonGroup jb;

    public Dosen_view() {
        this.setLayout(null);
        label7 = new JLabel("Opsi berkas  :");
        label7.setBounds(30, 50, 100, 30);
        this.add(label7);
        jc1 = new JCheckBox("Surat");
        jc1.setBounds(150, 50, 100, 30);
        jc1.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if(jc1.isSelected()){
                    jc.setEnabled(true);
                    jc2.setEnabled(false);
                    jt1.setEnabled(true);
                    jt2.setEnabled(true);
                    but1.setEnabled(true);
                    but2.setEnabled(true);
                    but4.setEnabled(true);
                }
            }
        });
        this.add(jc1);
        jc2 = new JCheckBox("Dokumen");
        jc2.setBounds(250, 50, 100, 30);
        jc2.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if(jc2.isSelected()){
                    jc.setEnabled(true);
                    jc1.setEnabled(false);
                    jt1.setEnabled(true);
                    jt2.setEnabled(true);
                    but1.setEnabled(true);
                    but2.setEnabled(true);
                    but4.setEnabled(true);
                }
            }
        });
        this.add(jc2);
        jb = new ButtonGroup();
        jb.add(jc1);
        jb.add(jc2);
        label1 = new JLabel("Konfirmasi dosen :");
        label1.setBounds(10, 10, 150, 30);
        this.add(label1);
        label3 = new JLabel("Periode  :");
        label3.setBounds(30, 110, 150, 30);
        this.add(label3);
        jt1 = new JTextField();
        jt1.setBounds(150, 110, 150, 30);
        jt1.setEnabled(false);
        this.add(jt1);
        jc = new JCheckBox("File sudah diterima");
        jc.setBounds(30, 200, 150, 35);
        jc.setEnabled(false);
        this.add(jc);
        label3 = new JLabel("Note :" + "\nConfirm jika sudah selesai");
        label3.setBounds(30, 240, 250, 30);
        this.add(label3);
        but1 = new JButton("CONFIRM");
        but1.setBounds(180, 300, 150, 30);
        but1.setEnabled(false);
        but1.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if (jc1.isSelected()) {
                    String a = jt1.getText();
                    String b = jt2.getText();
                    try {
                        PengendaliPeriksaSuratDokumen.confirmTabelSurat(a,b);
                    } catch (SQLException ex) {
                        Logger.getLogger(Dosen_view.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }else{
                    String a = jt1.getText();
                    String b = jt2.getText();
                    try {
                        PengendaliPeriksaSuratDokumen.confirmTabelDokumen(a,b);
                    } catch (SQLException ex) {
                        Logger.getLogger(Dosen_view.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        });
        this.add(but1);
        but2 = new JButton("RESET");
        but2.setBounds(340, 300, 150, 30);
        but2.setEnabled(false);
        this.add(but2);
        but2.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if(JOptionPane.showConfirmDialog(null, "Data field akan hilang")==0){
                jt1.setText(null);
                jt2.setText(null);
                jt1.setEnabled(false);
                jt2.setEnabled(false);
                jc.setSelected(false);
                jc1.setSelected(false);
                jc1.setEnabled(true);
                jc2.setSelected(false);
                jc2.setEnabled(true);
                jb.clearSelection();
                jc.setEnabled(false);
                but1.setEnabled(false);
                but2.setEnabled(false);
                but4.setEnabled(false);
            }
            }
        });
        but3 = new JButton("EXIT");
        but3.setBounds(500, 300, 150, 30);
        but3.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                JFrame frame = new JFrame();
                FrameUtama fr = new FrameUtama();
                fr.transferFocusBackward();
            }
        });
        this.add(but3);
        label5 = new JLabel("(s/d)");
        label5.setBounds(315, 105, 80, 30);
        this.add(label5);
        jt2 = new JTextField();
        jt2.setBounds(360, 110, 150, 30);
        jt2.setEnabled(false);
        this.add(jt2);
        but4 = new JButton("Cari");
        but4.setBounds(530, 110, 80, 30);
        but4.setEnabled(false);
        but4.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if (jc1.isSelected()) {
                    try {
                        String a = jt1.getText();
                        String b = jt2.getText();
                        JFrame test = new JFrame();
                        PanelLihatDaftarSurat ptk = new PanelLihatDaftarSurat(a,b);
                        test.add(ptk);
                        test.getContentPane().add(ptk);
                        test.setLocation(100, 100);
                        test.setSize(1200, 500);
                        test.setVisible(true);
                        test.setTitle("Panel lihat daftar surat");
                    } catch (SQLException ex) {
                        Logger.getLogger(Dosen_view.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } else {
                    try {
                        String a = jt1.getText();
                        String b = jt2.getText();
                        JFrame test = new JFrame();
                        PanelLihatDaftarDokumen ptk = new PanelLihatDaftarDokumen(a,b);
                        test.add(ptk);
                        test.getContentPane().add(ptk);
                        test.setLocation(100, 100);
                        test.setSize(1200, 500);
                        test.setVisible(true);
                        test.setTitle("Panel lihat daftar dokumen");
                    } catch (SQLException ex) {
                        Logger.getLogger(Dosen_view.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        });
        this.add(but4);
    }
}
